package chap6.p2;

public class People {
    public static int check(String strage) throws Exception{
        int age=Integer.parseInt(strage); //转换字符串为 int 型
        if(age<0)
            throw new Exception("年龄不能为负数！");
        return age;
    }
    public static void main(String[] args) {
        try{
            int myage=check("-101");
            System.out.println(myage);
        }catch(Exception e){
            System.out.println("数据逻辑错误！");
            System.out.println("原因："+e.getMessage());
        }
    }
}
